package com.jeewt.dao;

import com.jeewt.util.MybatisGeneratorUtil;
import com.jeewt.util.PropertiesFileUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 代码生成类
 * Created by Wang Xishou on 2018/2/11 0011.
 */
public class Generator {
    //根据命名规范，只修改此常量值即可
    private static String MODULE = "jeewt";
    private static String DATABASE = "jeewt";
    private static String TABLE_PREFIX = "jeewt";
    private static String PACKAGE_NAME = "com.jeewt";
    private static String JDBC_DRIVER = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.driver");
    private static String JDBC_URL = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.url");
    private static String JDBC_USERNAME = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.username");
    private static String JDBC_PASSWORD = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.password");

    //需要insert 后返回主键的表配置，key:表名,value:主键名
    private static Map<String, String> LAST_INSERT_ID_TABLES = new HashMap<>();
    static {
        LAST_INSERT_ID_TABLES.put("jeewt_user", "user_id");
    }

    /**
     * 自动代码生成
     * @param args
     */
    public static void main(String[] args)throws Exception{
        System.out.println("JDBC_DRIVER:"+JDBC_DRIVER);
        System.out.println("JDBC_URL:"+JDBC_URL);
        System.out.println("JDBC_USERNAME:"+JDBC_USERNAME);
        System.out.println("JDBC_PASSWORD:"+JDBC_PASSWORD);
        System.out.println("MODULE:"+MODULE);
        System.out.println("DATABASE:"+DATABASE);
        System.out.println("TABLE_PREFIX:"+TABLE_PREFIX);
        System.out.println("PACKAGE_NAME:"+PACKAGE_NAME);
        System.out.println("LAST_INSERT_ID_TABLES:"+LAST_INSERT_ID_TABLES);
        MybatisGeneratorUtil.generator(JDBC_DRIVER, JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD, MODULE, DATABASE, TABLE_PREFIX, PACKAGE_NAME, LAST_INSERT_ID_TABLES);
    }
}
